package demo4j.repo;

import apijson.JSONObject;
import apijson.JSONResponse;
import apijson.RequestMethod;
import apijson.framework.APIJSONParser;
import apijson.orm.JSONRequest;
import demo4j.model.User;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class UserRepository {
    @Cacheable(cacheNames = "user", key = "#userId")
    public User findById(Long userId) {
        String USER_ = User.class.getSimpleName();
        JSONResponse userRes = new JSONResponse(new APIJSONParser<>(RequestMethod.GET, false).parseResponse(new JSONRequest(USER_, new JSONObject(new User().setId(userId)).setJson("contactIdList,pictureList")).setFormat(true)));
        return userRes.getObject(USER_, User.class);
    }
}
